package com.vidmt.api.modules.sys.web;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.google.common.collect.Lists;
import com.vidmt.api.common.exceptions.UserNotExistsException;
import com.vidmt.api.common.pojo.ApiResultServer;
import com.vidmt.api.common.web.ApiController;
import com.vidmt.api.modules.sys.entity.User;
import com.vidmt.api.modules.sys.service.ImService;

/**
 * 用户Controller
 * 
 * @author ThinkGem
 * @version 2013-8-29
 */
@Controller
@RequestMapping(value = "${adminPath}/web/user/ali")
public class WebAliImController extends ApiController {
	private static final Logger log = LoggerFactory.getLogger(WebAliImController.class);
	@Autowired
	private ImService imService;

	@RequestMapping(value = { "/index.html" })
	public String index(Model model) {
		return "modules/user/aliuser";
	}

	@ResponseBody
	@RequestMapping(value = { "/list.*" })
	public ApiResultServer list() {
		List<User> list = Lists.newArrayList();
		int len=10;
		for(int i=99990;i<100100;i+=len){
			Long[] uids=new Long[len];
			for(int j=0;j<len;j++){
				uids[j]=Long.valueOf((i+j));
			}
			try {
				List<User> userlist = imService.findAliUsers(uids);
				list.addAll(userlist);
			} catch (UserNotExistsException e) {
				System.err.println("no user:"+i+"/"+(i+len));
			}
		}
			
		return new ApiResultServer(list);
	}

	@ResponseBody
	@RequestMapping(value = { "/delete.*" })
	public ApiResultServer delete(Long uid) {
		imService.deleteUser(uid);
		return new ApiResultServer();
	}
}
